# !/usr/bin/env python
# -*-coding:utf-8 -*-

"""
# Author     ：skyTree
# version    ：python 3.11
# Description：引入项目配置
"""
from flask import Flask
from flask_cors import CORS
from config import config_dict
from flask_sqlalchemy import SQLAlchemy

db = SQLAlchemy()


def create_app(config_name):
    app = Flask(__name__, static_folder='../static')

    # 引入配置
    config_obj = config_dict.get(config_name)
    app.config.from_object(config_obj)

    # 初始化数据库配置
    db.init_app(app)


    # 引入视图
    from api.user import user_blue
    app.register_blueprint(user_blue)

    from api.menu import menu_blue
    app.register_blueprint(menu_blue)

    from api.role import role_blue
    app.register_blueprint(role_blue)

    from api.category import category_blue
    app.register_blueprint(category_blue)

    from api.attrs import attrs_blue
    app.register_blueprint(attrs_blue)

    from api.goods import goods_blue
    app.register_blueprint(goods_blue)

    from api.order import order_blue
    app.register_blueprint(order_blue)

    CORS(app)
    return app
